﻿package src {
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	public class Letter extends MovieClip {
		private var val:Number;
		private var vx:Number = 0;
		private var vy:Number = 0;
		private var shape:TextField;
		public function Letter(str:String, color:uint = 0xcccccc, size:int = 10, area:int = 0, speed:Number = 1) {
			val = speed;
			
			shape = new TextField();
			shape.text = str;
			shape.autoSize = "left";
			shape.selectable = false;
			shape.mouseEnabled = false;
			
			shape.setTextFormat(new TextFormat("", size, color, true));
			
			
			addChild(shape);
			x = mouseX + Math.random() * area * 2 - area;
			y = mouseY + Math.random() * area * 2 - area;
			addEventListener(Event.ENTER_FRAME, moveHd);
		}
		private function moveHd(e:Event):void {
			x += vx;
			y += vy;
			alpha -= 0.05;
			vx = vx+((Math.random()*2)-1);
			vy = vy+((Math.random()*2)-1);
			vx = vx*val;
			vy = vy*val;
			//
			if (((((x>stage.stageWidth) || (x<0)) || (y>stage.stageHeight)) || (y<0)) || (alpha<0.1)) {
				remove();
			}
		}
		private function remove():void {
			removeEventListener(Event.ENTER_FRAME, moveHd);
			if (parent) {
				parent.removeChild(this);
			}
		}
	}
}